import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;

public class day_06_IO_Test_05 {
    public static void main(String[] args) throws IOException {
        // 对文件中的段落进行排序
        BufferedReader bufferedReader = new BufferedReader(new FileReader("csb.txt",Charset.forName("UTF-8")));
        String line;
        ArrayList<String> list = new ArrayList<>();

        // 读取文件内容
        while ((line = bufferedReader.readLine()) != null) {
            list.add(line);
        }

        // 排序
        Collections.sort(list, (o1, o2) -> {
            int i1 = Integer.parseInt(o1.split("\\.")[0]);
            int i2 = Integer.parseInt(o2.split("\\.")[0]);
            return i1 - i2;
        });

        bufferedReader.close();

        // 将排序后的内容写入文件
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("result.txt",Charset.forName("UTF-8")));
        for (String s : list) {
            bufferedWriter.write(s);
            bufferedWriter.newLine();
        }
        bufferedWriter.close();
    }
}
